package com.example.f8399.testdemo.utils;

import android.Manifest;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;

import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;

/**
 * Created by f8399 on 2018/9/20.
 */

public class PermissionsUtil {
    public static final int REQUST_PERMISSION_CODE_CAMERA = 0x2671;
    /**
     * 判断并申请拍照权限
     * @param activity 界面
     * @return
     */
    @AfterPermissionGranted(REQUST_PERMISSION_CODE_CAMERA)
    public static boolean hasCameraPermission(AppCompatActivity activity) {
        boolean isHave = false;
        String pers[] = {Manifest.permission.CAMERA,Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE};
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (EasyPermissions.hasPermissions(activity, pers)) {
                isHave = true;
            }else {
                EasyPermissions.requestPermissions(activity,"请允许拍照权限才可以进行后续操作", REQUST_PERMISSION_CODE_CAMERA,pers);
            }
        }else {
            isHave = true;
        }

        return isHave;
    }
}
